import { segment } from 'icqq';
import{isNotNull, synchronization}from'../mz/mz.js'
import { __PATH } from '../mz/mz.js';
import {
    Read_player,
    existplayer,
    Write_player,
    Write_thing,
    getplayerdang,
  } from '../mz/mz.js';
  import fs from 'fs';
export class chenghao extends plugin {
    constructor() {
      super({
        name: 'Yunzai_Bot_chenghao',
        dsc: '网站模块',
        event: 'message',
        priority: 600,
        rule: [
          {
            reg: /^(#|\/)赋予称号.*/,
            fnc: 'givechenghao',
          },
          {
            reg: /^(#|\/)我的称号.*/,
            fnc: 'mychenghao',
          },
          {
            reg: /^(#|\/)对方的称号.*/,
            fnc: 'hischenghao',
          },
      
        ],
      });
    }
    async givechenghao(e){
        if (!e.isMaster) {
            e.reply(`只有主人可以发称号`)
            return;
          }
        let usr_qq = e.user_id;
        let didian = e.msg.replace(/(\/|#)赋予称号/, '').trim();
        let isat = e.message.some(item => item.type === 'at');
        if (!isat) {
          return;
        }
        let atItem = e.message.filter(item => item.type === 'at'); //获取at信息
        let B_qq = atItem[0].qq; //对方qq
        let ifexistplay = await existplayer(B_qq);
        if (!ifexistplay) {
          e.reply("对方没有存档无法给予");
          return;
        }
        let player =await Read_player(B_qq)
        if (!isNotNull(player.称号)) {
            e.reply("请让主人使用名字同步")
            return;
        }
        player.称号 = didian
        await Write_player(usr_qq,player)
        e.reply([segment.at(B_qq),`恭喜获得称号${didian}`])
        return;
    }
    async mychenghao(e){
        let usr_qq = e.user_id;
        let player =await Read_player(usr_qq)
        let ifexistplay = await existplayer(usr_qq);
        if (!ifexistplay) {
          e.reply("没有存档");
          return;
        }
        if (!isNotNull(player.称号)) {
            e.reply("请让主人使用名字同步")
            return;
        }
        e.reply([segment.at(B_qq),`你的称号为${player.称号}`])
    }
    async hischenghao(e){
        let usr_qq = e.user_id;
        let isat = e.message.some(item => item.type === 'at');
        if (!isat) {
          return;
        }
        let atItem = e.message.filter(item => item.type === 'at'); //获取at信息
        let B_qq = atItem[0].qq; //对方qq
        let player =await Read_player(B_qq)
        let ifexistplay = await existplayer(B_qq);
        if (!ifexistplay) {
          e.reply("没有存档");
          return;
        }
        if (!isNotNull(player.称号)) {
            e.reply("请让主人使用名字同步")
            return;
        }
        e.reply([segment.at(B_qq),`对方的称号为${player.称号}`])
    }
   
    
    }





